package com.xueyiyue.xueyiyue.service.impl;

import com.xueyiyue.xueyiyue.dao.UserMapper;
import com.xueyiyue.xueyiyue.model.entity.*;
import com.xueyiyue.xueyiyue.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author chenlixian
 * @description TODO
 * @date 2020/12/21 10:31
 */
@Slf4j
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;


    @Override
    public List<JobsListVo> getFavoriteJobsList(Favorite favorite) {
        return userMapper.getFavoriteJobsList(favorite);
    }

    @Override
    public List<NewsListVo> getFavoriteNewsList(Favorite favorite) {
        return userMapper.getFavoriteNewsList(favorite);
    }

    @Override
    public List<JobsListVo> getJobsList(JobsListVo jobsListVo) {
        return userMapper.getJobsList(jobsListVo);
    }

    @Override
    public List<NewsListVo> getNewsList(NewsListVo newsListVo) {
        return userMapper.getNewsList(newsListVo);
    }

    @Override
    public List<Dictionary> getDicData(Dictionary dictionary) {
        return userMapper.getDicData(dictionary);
    }

    @Override
    public UserInfo getUserInfo(String openId) {
        return userMapper.getUserInfo(openId);
    }

    @Override
    public Integer enterUserInfo(UserInfo userInfo) {
        int count = 0;
        try{
        count = userMapper.addUser(userInfo);}
        catch (Exception e){
            count = userMapper.updateUser(userInfo);
        }
        return count;
    }

    @Override
    public UserInfoDetail getUserInfoDetail(UserInfoDetail userInfoDetail) {
        return userMapper.getUserInfoDetail(userInfoDetail);
    }

    @Override
    public Integer enterUserInfoDetail(UserInfoDetail userInfoDetail) {
        int count = 0;
        try{
            count = userMapper.addUserDetail(userInfoDetail);}
        catch (Exception e){
            count = userMapper.updateUserDetail(userInfoDetail);
        }
        return count;
    }

    @Override
    public Integer createNews(NewsVo newsVo) {
        return userMapper.createNews(newsVo);
    }

    @Override
    public Integer deleteNews(NewsVo newsVo) {
        return userMapper.deleteNews(newsVo);
    }

    @Override
    public Integer deleteJobs(JobsVo jobsVo) {
        return userMapper.deleteJobs(jobsVo);
    }

    @Override
    public Integer createJobs(JobsVo jobsVo) {
        return userMapper.createJobs(jobsVo);
    }

    @Override
    public Integer favorite(Favorite favorite) {
        Integer r = 0;
        if(favorite.getFavorite() == 0){
            r=userMapper.deleteFavorite(favorite);
        }
        else
            r=userMapper.insertFavorite(favorite);
        return r;
    }
}
